package cn.edu.lzu.service.impl;

import cn.edu.lzu.common.assist.ResponseResult;
import cn.edu.lzu.dao.FillLabItemMapper;
import cn.edu.lzu.dao.LabItemValueMapper;
import cn.edu.lzu.entity.Examiner;
import cn.edu.lzu.entity.FillLabItem;
import cn.edu.lzu.service.LabItemValueService;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.sql.Timestamp;

/**
 * @PackageName: cn.edu.lzu.service.impl
 * @ClassName: LabItemValueServiceImpl
 * @Description: TODO
 * @Author: 张琦[QQ:3098086691]
 * @Date: 2020/4/5 12:03
 * @Version: 1.0
 */
@Service
@Transactional
public class LabItemValueServiceImpl implements LabItemValueService {
    @Resource
    private LabItemValueMapper labItemValueMapper;
    @Resource
    private FillLabItemMapper fillLabItemMapper;

    @Override
    public ResponseResult submitClauseValue(Examiner examiner, String submitValue) {
        String[] IdValue=submitValue.split("@");
        System.out.println(IdValue);
        ResponseResult responseResult=new ResponseResult();
        for(int i=0; i<IdValue.length; i++){
            String[] iv=IdValue[i].split("#");
            String[] ids=iv[0].split(",");
            int result=labItemValueMapper.updAddValue(Integer.valueOf(ids[0]), Integer.valueOf(ids[1]), examiner.getUnitId(), iv[1]);
            if(result!=1){
                responseResult.setCode(0);
                responseResult.setMsg("失败！");
                return responseResult;
            }
        }
        FillLabItem fillLabItem=new FillLabItem();
        fillLabItem.setFilled(true);
        fillLabItem.setExamineTime(new Timestamp(System.currentTimeMillis()));
        fillLabItem.setExaminerId(examiner.getExaminerId());
        fillLabItem.setFillLabItemId(Integer.valueOf(IdValue[0].split("#")[0].split(",")[0]));
        int fillResult=fillLabItemMapper.updLabItemStatusFilled(fillLabItem);
        responseResult.setCode(1);
        responseResult.setMsg("成功！");
        return responseResult;
    }
}
